Skip to content

Commit

Permalink
Fix to the signature of AzraelReader
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Jan 8, 2023
1 parent 1a5d4b1 commit 11d0b46
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 51 deletions.
7 changes: 6 additions & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/BlobSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public BitSequence read(BitSequence s) throws ReadException
public BitSequence read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence s = (BitSequence) o;
long length = m_intSchema.read(s).longValue();
if (s.size() < length)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Buffy/src/ca/uqac/lif/azrael/buffy/BooleanSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ protected BooleanSchema()
}

@Override
public Boolean read(BitSequence t) throws ReadException
public Boolean read(Object o) throws ReadException
{
return (Boolean) super.read(t);
return (Boolean) super.read(o);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public byte[] read(BitSequence o) throws ReadException
public byte[] read(Object o) throws ReadException
{
BitSequence seq = (BitSequence) BlobSchema.blob32.read(o);
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence s = (BitSequence) o;
BitSequence seq = (BitSequence) BlobSchema.blob32.read(s);
return seq.toByteArray();
}
}
7 changes: 6 additions & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/ClassSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ public ClassSchema(Class<?> ... classes)
}

@Override
public Class<?> read(BitSequence t) throws ReadException
public Class<?> read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
BitSequence is_shortcut = t.truncatePrefix(1);
if (is_shortcut.get(0))
{
Expand Down
7 changes: 6 additions & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/EnumSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ public EnumSchema(Object ... entries)
}

@Override
public Object read(BitSequence t) throws ReadException
public Object read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
BitSequence k = t.truncatePrefix(m_intSchema.getWidth());
if (!m_fromBits.containsKey(k))
{
Expand Down
11 changes: 8 additions & 3 deletions Source/Buffy/src/ca/uqac/lif/azrael/buffy/FixedMapSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,21 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public Map<String,?> read(BitSequence s) throws ReadException
public Map<String,?> read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence s = (BitSequence) o;
Map<String,Object> map = new HashMap<String,Object>();
for (String k : m_keys)
{
BitSequence has_entry = s.truncatePrefix(1);
if (has_entry.get(0))
{
Object o = m_valueType.read(s);
map.put(k, o);
Object o2 = m_valueType.read(s);
map.put(k, o2);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ public HuffstringSchema(HuffNode tree)
}

@Override
public String read(BitSequence t) throws ReadException
public String read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
StringBuilder out = new StringBuilder();
String c = null;
do
Expand Down
7 changes: 6 additions & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/IntSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public Number read(BitSequence bs) throws ReadException
public Number read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence bs = (BitSequence) o;
long i_value = 0;
if (m_numBits > bs.size())
{
Expand Down
18 changes: 14 additions & 4 deletions Source/Buffy/src/ca/uqac/lif/azrael/buffy/ListSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public ListSchema(Schema element_schema)
}

@Override
public List<?> read(BitSequence t) throws ReadException
public List<?> read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
int size = IntSchema.int16.read(t).intValue();
if (t.size() < size)
{
Expand All @@ -45,13 +50,18 @@ public List<?> read(BitSequence t) throws ReadException
return read(t, size);
}

protected List<Object> read(BitSequence t, int size) throws ReadException
protected List<Object> read(Object o, int size) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
List<Object> list = new ArrayList<Object>(size);
for (int i = 0; i < size; i++)
{
Object o = m_elementSchema.read(t);
list.add(o);
Object o2 = m_elementSchema.read(t);
list.add(o2);
}
return list;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/NullSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected NullSchema()
}

@Override
public Object read(BitSequence t) throws ReadException
public Object read(Object o) throws ReadException
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Buffy/src/ca/uqac/lif/azrael/buffy/NupleSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public NupleSchema(Schema element_schema, int size)
}

@Override
public List<?> read(BitSequence t) throws ReadException
public List<?> read(Object o) throws ReadException
{
return read(t, m_size);
return read(o, m_size);
}

@Override
Expand Down
28 changes: 14 additions & 14 deletions Source/Buffy/src/ca/uqac/lif/azrael/buffy/ReflectiveSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ReflectiveSchema()
}

@Override
public Schema read(BitSequence t) throws ReadException
public Schema read(Object t) throws ReadException
{
return (Schema) super.read(t);
}
Expand All @@ -55,7 +55,7 @@ protected ByteArrayReflectiveSchema()
}

@Override
public ByteArraySchema read(BitSequence t) throws ReadException
public ByteArraySchema read(Object o) throws ReadException
{
return ByteArraySchema.instance;
}
Expand All @@ -75,7 +75,7 @@ protected ListReflectiveSchema()
}

@Override
public ListSchema read(BitSequence t) throws ReadException
public ListSchema read(Object t) throws ReadException
{
Schema element_schema = ReflectiveSchema.this.read(t);
return new ListSchema(element_schema);
Expand All @@ -96,7 +96,7 @@ public BitSequence print(Object o) throws PrintException

protected class FixedMapReflectiveSchema implements Schema
{
protected static final ListSchema s_listSchema = new ListSchema(StringBlobSchema.instance);
protected final ListSchema s_listSchema = new ListSchema(StringBlobSchema.instance);

protected FixedMapReflectiveSchema()
{
Expand All @@ -105,7 +105,7 @@ protected FixedMapReflectiveSchema()

@SuppressWarnings("unchecked")
@Override
public FixedMapSchema read(BitSequence t) throws ReadException
public FixedMapSchema read(Object t) throws ReadException
{
List<String> keys = (List<String>) s_listSchema.read(t);
Schema value_type = ReflectiveSchema.this.read(t);
Expand All @@ -128,9 +128,9 @@ public BitSequence print(Object o) throws PrintException

protected class VariantReflectiveSchema implements Schema
{
protected static final ListSchema s_classListSchema = new ListSchema(new ClassSchema(Boolean.class, Integer.class, String.class, List.class, Map.class));
protected final ListSchema s_classListSchema = new ListSchema(new ClassSchema(Boolean.class, Integer.class, String.class, List.class, Map.class));

protected static final ListSchema s_blobListSchema = new ListSchema(BlobSchema.blob32);
protected final ListSchema s_blobListSchema = new ListSchema(BlobSchema.blob32);

protected VariantReflectiveSchema()
{
Expand All @@ -139,7 +139,7 @@ protected VariantReflectiveSchema()

@SuppressWarnings("unchecked")
@Override
public VariantSchema read(BitSequence t) throws ReadException
public VariantSchema read(Object t) throws ReadException
{
List<Class<?>> class_names = (List<Class<?>>) s_classListSchema.read(t);
List<BitSequence> schemas = (List<BitSequence>) s_blobListSchema.read(t);
Expand Down Expand Up @@ -199,7 +199,7 @@ protected BooleanReflectiveSchema()
}

@Override
public BooleanSchema read(BitSequence t) throws ReadException
public BooleanSchema read(Object t) throws ReadException
{
return BooleanSchema.instance;
}
Expand All @@ -223,7 +223,7 @@ protected StringBlobReflectiveSchema()
}

@Override
public StringBlobSchema read(BitSequence t) throws ReadException
public StringBlobSchema read(Object t) throws ReadException
{
return StringBlobSchema.instance;
}
Expand All @@ -247,7 +247,7 @@ protected SmallsciiReflectiveSchema()
}

@Override
public SmallsciiSchema read(BitSequence t) throws ReadException
public SmallsciiSchema read(Object t) throws ReadException
{
return SmallsciiSchema.instance;
}
Expand All @@ -271,7 +271,7 @@ protected BlobReflectiveSchema()
}

@Override
public BlobSchema read(BitSequence t) throws ReadException
public BlobSchema read(Object t) throws ReadException
{
return BlobSchema.blob32;
}
Expand All @@ -295,7 +295,7 @@ protected IntReflectiveSchema()
}

@Override
public IntSchema read(BitSequence t) throws ReadException
public IntSchema read(Object t) throws ReadException
{
boolean signed = BooleanSchema.instance.read(t);
int num_bits = IntSchema.int8.read(t).intValue();
Expand Down Expand Up @@ -329,7 +329,7 @@ public SelfDescribedSchema(Schema s)
}

@Override
public Object read(BitSequence t) throws ReadException
public Object read(Object t) throws ReadException
{
// TODO Auto-generated method stub
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ public static class SelfDescribedObjectSchema implements Schema
protected static final ReflectiveSchema s_reflectiveSchema = new ReflectiveSchema();

@Override
public SelfDescribedObject read(BitSequence t) throws ReadException
public SelfDescribedObject read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
Schema o_s = s_reflectiveSchema.read(t);
Object o = o_s.read(t);
return new SelfDescribedObject(o_s, o);
Object o2 = o_s.read(t);
return new SelfDescribedObject(o_s, o2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public String read(BitSequence s) throws ReadException
public String read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence s = (BitSequence) o;
StringBuilder sb = new StringBuilder();
while (s.size() >= 6)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ public BitSequence print(Object o) throws PrintException
}

@Override
public String read(BitSequence o) throws ReadException
public String read(Object ob) throws ReadException
{
if (!(ob instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence o = (BitSequence) ob;
byte[] bytes = BlobSchema.blob16.read(o).toByteArray();
return new String(bytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public abstract class StringSchema implements Schema
public abstract BitSequence print(Object o) throws PrintException;

@Override
public abstract String read(BitSequence s) throws ReadException;
public abstract String read(Object s) throws ReadException;
}
7 changes: 6 additions & 1 deletion Source/Buffy/src/ca/uqac/lif/azrael/buffy/VariantSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ protected VariantSchema add(SchemaEntry e)
}

@Override
public Object read(BitSequence t) throws ReadException
public Object read(Object o) throws ReadException
{
if (!(o instanceof BitSequence))
{
throw new ReadException("Expected a bit sequence");
}
BitSequence t = (BitSequence) o;
BitSequence b_id = t.truncatePrefix(s_int.getWidth());
if (!m_schemaMap.containsKey(b_id))
{
Expand Down
Loading

0 comments on commit 11d0b46

Please sign in to comment.