public void Read_Boolean(byte[] buf, bool want) { using (var s = new OtpInputStream(buf)) { Assert.AreEqual(want, s.ReadBoolean()); } }
private static Cell ParseCell(OtpInputStream s, int i, Column[] cols) { string msg; Column col = cols[i]; byte tag = s.Peek(); switch (tag) { case OtpExternal.NilTag: tag = s.Read1(); // NB: actually consume the byte return(new Cell()); case OtpExternal.BinTag: if (col.Type == ColumnType.Varchar || col.Type == ColumnType.Blob) { return(new Cell(s.ReadBinaryAsString())); } else { throw OnBadTag(tag, col, ColumnType.Varchar, ColumnType.Blob); } case OtpExternal.SmallIntTag: case OtpExternal.IntTag: case OtpExternal.SmallBigTag: case OtpExternal.LargeBigTag: long val = s.ReadLong(); switch (col.Type) { case ColumnType.SInt64: return(new Cell(val, isUnixTimestamp: false)); case ColumnType.Timestamp: return(new Cell(val, isUnixTimestamp: true)); default: throw OnBadTag(tag, col, ColumnType.SInt64, ColumnType.Timestamp); } case OtpExternal.FloatTag: case OtpExternal.NewFloatTag: if (col.Type != ColumnType.Double) { throw OnBadTag(tag, col, ColumnType.Double); } return(new Cell(s.ReadDouble())); case OtpExternal.AtomTag: if (col.Type != ColumnType.Boolean) { throw OnBadTag(tag, col, ColumnType.Boolean); } return(new Cell(s.ReadBoolean())); case OtpExternal.ListTag: int arity = s.ReadNil(); if (arity == 0) { // null cell return(new Cell()); } else { msg = string.Format( "Expected nil list, got one with arity {0}", arity); throw new InvalidOperationException(msg); } default: msg = string.Format( "Unknown cell type encountered, tag {0}, '{1}:{2}'", tag, col.Name, col.Type); throw new InvalidOperationException(msg); } }
private static Cell ParseCell(OtpInputStream s, int i, Column[] cols) { string msg; Column col = cols[i]; byte tag = s.Peek(); switch (tag) { case OtpExternal.NilTag: tag = s.Read1(); // NB: actually consume the byte return new Cell(); case OtpExternal.BinTag: if (col.Type == ColumnType.Varchar || col.Type == ColumnType.Blob) { return new Cell(s.ReadBinaryAsString()); } else { throw OnBadTag(tag, col, ColumnType.Varchar, ColumnType.Blob); } case OtpExternal.SmallIntTag: case OtpExternal.IntTag: case OtpExternal.SmallBigTag: case OtpExternal.LargeBigTag: long val = s.ReadLong(); switch (col.Type) { case ColumnType.SInt64: return new Cell(val, isUnixTimestamp: false); case ColumnType.Timestamp: return new Cell(val, isUnixTimestamp: true); default: throw OnBadTag(tag, col, ColumnType.SInt64, ColumnType.Timestamp); } case OtpExternal.FloatTag: case OtpExternal.NewFloatTag: if (col.Type != ColumnType.Double) { throw OnBadTag(tag, col, ColumnType.Double); } return new Cell(s.ReadDouble()); case OtpExternal.AtomTag: if (col.Type != ColumnType.Boolean) { throw OnBadTag(tag, col, ColumnType.Boolean); } return new Cell(s.ReadBoolean()); case OtpExternal.ListTag: int arity = s.ReadNil(); if (arity == 0) { // null cell return new Cell(); } else { msg = string.Format( "Expected nil list, got one with arity {0}", arity); throw new InvalidOperationException(msg); } default: msg = string.Format( "Unknown cell type encountered, tag {0}, '{1}:{2}'", tag, col.Name, col.Type); throw new InvalidOperationException(msg); } }