use of com.google.cloud.video.livestream.v1.Input in project red5-client by Red5.
the class DSRemotingClient method decodeResult.
/**
* Decode response received from remoting server.
*
* @param data
* Result data to decode
* @return Object deserialized from byte buffer data
*/
private Object decodeResult(IoBuffer data) {
log.debug("decodeResult - data limit: {}", (data != null ? data.limit() : 0));
processHeaders(data);
Input input = new Input(data);
String target = null;
byte b = data.get();
// look for SOH
if (b == 0) {
// 0
log.debug("NUL: {}", b);
// 1
log.debug("SOH: {}", data.get());
} else if (b == 1) {
// 1
log.debug("SOH: {}", b);
}
int targetUriLength = data.getShort();
log.debug("targetUri length: {}", targetUriLength);
target = input.readString(targetUriLength);
// 0
log.debug("NUL: {}", data.get());
// should be junk bytes ff, ff, ff, ff
int count = data.getInt();
if (count == -1) {
// 17
log.debug("DC1: {}", data.get());
count = 1;
} else {
data.position(data.position() - 4);
count = data.getShort();
}
if (count != 1) {
throw new RuntimeException("Expected exactly one result but got " + count);
}
String[] targetParts = target.split("[/]");
if (targetParts.length > 1) {
log.debug("Result sequence number: {}", targetParts[1]);
target = targetParts[2];
} else {
target = target.substring(1);
}
log.debug("Target: {}", target);
if ("onResult".equals(target)) {
// read return value
return input.readObject();
} else if ("onStatus".equals(target)) {
// read return value
return input.readObject();
}
// read return value
return Deserializer.deserialize(input, Object.class);
}
use of com.google.cloud.video.livestream.v1.Input in project red5-client by Red5.
the class DSRemotingClient method processHeaders.
/**
* Process any headers sent in the response.
*
* @param in
* Byte buffer with response data
*/
@Override
protected void processHeaders(IoBuffer in) {
log.debug("RemotingClient processHeaders - buffer limit: {}", (in != null ? in.limit() : 0));
// skip
int version = in.getUnsignedShort();
log.debug("Version: {}", version);
// the version by now, AMF3 is not yet implemented
int count = in.getUnsignedShort();
log.debug("Count: {}", count);
Input input = new Input(in);
for (int i = 0; i < count; i++) {
String name = input.getString();
log.debug("Name: {}", name);
boolean required = (in.get() == 0x01);
log.debug("Required: {}", required);
Object value = null;
int len = in.getInt();
log.debug("Length: {}", len);
// look for junk bytes ff,ff,ff,ff
if (len == -1) {
// 02
in.get();
len = in.getShort();
log.debug("Corrected length: {}", len);
value = input.readString(len);
} else {
value = Deserializer.deserialize(input, Object.class);
}
log.debug("Value: {}", value);
// XXX: this is pretty much untested!!!
if (RemotingHeader.APPEND_TO_GATEWAY_URL.equals(name)) {
// Append string to gateway url
appendToUrl = (String) value;
} else if (RemotingHeader.REPLACE_GATEWAY_URL.equals(name)) {
// Replace complete gateway url
url = (String) value;
// XXX: reset the <appendToUrl< here?
} else if (RemotingHeader.PERSISTENT_HEADER.equals(name)) {
// Send a new header with each following request
if (value instanceof Map<?, ?>) {
@SuppressWarnings("unchecked") Map<String, Object> valueMap = (Map<String, Object>) value;
RemotingHeader header = new RemotingHeader((String) valueMap.get("name"), (Boolean) valueMap.get("mustUnderstand"), valueMap.get("data"));
headers.put(header.getName(), header);
} else {
log.error("Expected Map but received {}", value);
}
} else {
log.warn("Unsupported remoting header \"{}\" received with value \"{}\"", name, value);
}
}
}
use of com.google.cloud.video.livestream.v1.Input in project red5-io by Red5.
the class AMF3IOTest method setupIO.
/**
* {@inheritDoc}
*/
@Override
void setupIO() {
// 1kb
buf = IoBuffer.allocate(0);
buf.setAutoExpand(true);
buf.setAutoShrink(true);
in = new Input(buf);
out = new Output(buf);
}
use of com.google.cloud.video.livestream.v1.Input in project red5-io by Red5.
the class AMF3IOTest method testVectorIntInput.
@Test
public void testVectorIntInput() {
log.debug("\n Testing Vector<int>");
// 0D090000000002000007D07FFFFFFF80000000
byte[] v = new byte[] { (byte) 0x0D, (byte) 0x09, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0xD0, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
in = new Input(IoBuffer.wrap(v));
List<Object> vectorOut = Deserializer.deserialize(in, null);
// [2, 2000, 2147483647, -2147483648]
assertNotNull(vectorOut);
assertEquals(vectorOut.size(), 4);
for (int i = 0; i < vectorOut.size(); i++) {
System.err.println("Vector: " + vectorOut.get(i));
}
resetOutput();
}
use of com.google.cloud.video.livestream.v1.Input in project red5-io by Red5.
the class AMF3IOTest method testVectorMixedInput.
@Test
public void testVectorMixedInput() {
log.debug("\n Testing Vector<Object>");
// 100700010607666f6f010a13256f72672e726564352e74673742e466f6f33000403
// [foo, null, org.red5.test.Foo3[foo=0]] // Foo3 is a class instance
byte[] v2 = new byte[] { (byte) 0x10, (byte) 0x07, (byte) 0x00, (byte) 0x01, (byte) 0x06, (byte) 0x07, (byte) 0x66, (byte) 0x6f, (byte) 0x6f, (byte) 0x01, (byte) 0x0a, (byte) 0x13, (byte) 0x25, (byte) 0x6f, (byte) 0x72, (byte) 0x67, (byte) 0x2e, (byte) 0x72, (byte) 0x65, (byte) 0x64, (byte) 0x35, (byte) 0x2e, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x46, (byte) 0x6f, (byte) 0x6f, (byte) 0x33, (byte) 0x00, (byte) 0x04, (byte) 0x03 };
in = new Input(IoBuffer.wrap(v2));
List<Object> vectorOut = Deserializer.deserialize(in, null);
assertNotNull(vectorOut);
assertEquals(vectorOut.size(), 3);
for (int i = 0; i < vectorOut.size(); i++) {
System.err.println("Vector: " + vectorOut.get(i));
}
resetOutput();
}
Aggregations