本文整理汇总了C#中System.ByteBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.put方法的具体用法?C# ByteBuffer.put怎么用?C# ByteBuffer.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Blob
/// <summary>
/// Create a new Blob from an existing ByteBuffer. IMPORTANT: If copy is
/// false, after calling this constructor, if you keep a pointer to the buffer
/// then you must treat it as immutable and promise not to change it.
/// </summary>
///
/// <param name="buffer"></param>
/// <param name="copy"></param>
public Blob(ByteBuffer buffer, bool copy)
{
this.haveHashCode_ = false;
if (buffer != null) {
if (copy) {
buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(buffer.remaining());
// Put updates buffer.position(), so save and restore it.
int savePosition = buffer.position();
buffer_.put(buffer);
buffer.position(savePosition);
buffer_.flip();
} else
buffer_ = buffer.slice();
} else
buffer_ = null;
}
示例2: reverse
/// <summary>
/// Reverse the bytes in buffer starting at position, up to but not including
/// limit.
/// </summary>
///
/// <param name="buffer"></param>
/// <param name="position"></param>
/// <param name="limit"></param>
public static void reverse(ByteBuffer buffer, int position, int limit)
{
int from = position;
int to = limit - 1;
while (from < to) {
// swap
byte temp = buffer.get(from);
buffer.put(from, buffer.get(to));
buffer.put(to, temp);
--to;
++from;
}
}
示例3: read
// fh is filehandle passed from open
//throws FuseException
public int read(String path, Object fh, ByteBuffer buf, long offset)
{
if (fh is FH)
{
F f = (F)((FH)fh).n;
buf.put(f.content, (int)offset, System.Math.Min(buf.remaining(), f.content.Length - (int)offset));
return 0;
}
return Errno.EBADF;
}
示例4: getxattr
//
// XattrSupport implementation
/**
* This method will be called to get the value of the extended attribute
*
* @params path the path to file or directory containing extended attribute
* @params name the name of the extended attribute
* @params dst a ByteBuffer that should be filled with the value of the extended attribute
* @return 0 if Ok or errno when error
* @throws fuse.FuseException an alternative to returning errno is to throw this exception with errno initialized
* @throws java.nio.BufferOverflowException
* should be thrown to indicate that the given <code>dst</code> ByteBuffer
* is not large enough to hold the attribute's value. After that <code>getxattr()</code> method will
* be called again with a larger buffer.
*/
//throws FuseException, BufferOverflowException
public int getxattr(String path, String name, ByteBuffer dst)
{
N n = lookup(path);
if (n == null)
return Errno.ENOENT;
byte[] value = null;
n.xattrs.TryGetValue(name, out value);
if (value == null)
return Errno.ENOATTR;
dst.put(value);
return 0;
}
示例5: writeHeader
/**
* Write the length of the compressed bytes. Life is much easier if the
* header is constant length, so just use 3 bytes. Considering most of the
* codecs want between 32k (snappy) and 256k (lzo, zlib), 3 bytes should
* be plenty. We also use the low bit for whether it is the original or
* compressed bytes.
* @param buffer the buffer to write the header to
* @param position the position in the buffer to write at
* @param val the size in the file
* @param original is it uncompressed
*/
private static void writeHeader(
ByteBuffer buffer,
int position,
int val,
bool original)
{
buffer.put(position, (byte)((val << 1) + (original ? 1 : 0)));
buffer.put(position + 1, (byte)(val >> 7));
buffer.put(position + 2, (byte)(val >> 15));
}
示例6: readDirect
public static void readDirect(Stream file, int len, ByteBuffer directBuf)
{
// TODO: HDFS API is a mess, so handle all kinds of cases.
// Before 2.7, read() also doesn't adjust position correctly, so track it separately.
int pos = directBuf.position(), startPos = pos, endPos = pos + len;
try
{
while (pos < endPos)
{
int count = readByteBuffer(file, directBuf);
if (count < 0) throw new EndOfStreamException();
Debug.Assert(count != 0, "0-length read: " + (endPos - pos) + "@" + (pos - startPos));
pos += count;
Debug.Assert(pos <= endPos, "Position " + pos + " > " + endPos + " after reading " + count);
directBuf.position(pos);
}
}
catch (NotSupportedException)
{
Debug.Assert(pos == startPos);
// Happens in q files and such.
RecordReaderImpl.LOG.error("Stream does not support direct read; we will copy.");
byte[] buffer = new byte[len];
file.readFully(buffer, 0, buffer.Length);
directBuf.put(buffer);
}
directBuf.position(startPos);
directBuf.limit(startPos + len);
}
示例7: setByteBuffer
public void setByteBuffer(ByteBuffer result, int offset, int length)
{
result.clear();
int currentChunk = offset / chunkSize;
int currentOffset = offset % chunkSize;
while (length > 0)
{
int currentLength = Math.Min(length, chunkSize - currentOffset);
result.put(data[currentChunk], currentOffset, currentLength);
length -= currentLength;
currentChunk++;
currentOffset = 0;
}
}
示例8: transmitSingleObject
/**
* Send an object through the telemetry link.
* @throws IOException
* @param[in] obj Object handle to send
* @param[in] type Transaction type \return Success (true), Failure (false)
*/
private bool transmitSingleObject(UAVObject obj, int type, bool allInstances)
{
int length;
int allInstId = uavConsts.ALL_INSTANCES;
ByteBuffer bbuf = new ByteBuffer(uavConsts.MAX_PACKET_LENGTH);
// Determine data length
if (type == uavConsts.TYPE_OBJ_REQ || type == uavConsts.TYPE_ACK)
{
length = 0;
}
else
{
length = obj.getNumBytes();
}
// Setup type and object id fields
bbuf.put((byte)(uavConsts.SYNC_VAL & 0xff));
bbuf.put((byte)(type & 0xff));
bbuf.putShort((UInt16)(length + 2 /* SYNC, Type */+ 2 /* Size */+ 4 /* ObjID */+ (obj
.isSingleInstance() ? 0 : 2)));
bbuf.putUint32((UInt32)obj.getObjID());
// Setup instance ID if one is required
if (!obj.isSingleInstance())
{
// Check if all instances are requested
if (allInstances)
bbuf.putShort((UInt16)(allInstId & 0xffff));
else
bbuf.putShort((UInt16)(obj.getInstID() & 0xffff));
}
// Check length
if (length >= uavConsts.MAX_PAYLOAD_LENGTH)
return false;
// Copy data (if any)
if (length > 0)
try
{
if (obj.pack(bbuf) == 0)
return false;
}
catch (Exception e)
{
// TODO Auto-generated catch block
Debug.Write(e.Message);
return false;
}
// Calculate checksum
bbuf.put((byte)(CRC.updateCRC(0, bbuf.array(), bbuf.position()) & 0xff));
int packlen = bbuf.position();
bbuf.position(0);
byte[] dst = new byte[packlen];
bbuf.get(dst, 0, packlen);
if (type == uavConsts.TYPE_OBJ_ACK || type == uavConsts.TYPE_OBJ_REQ)
{
// Once we send a UAVTalk packet that requires an ack or object let's set up
// the transaction here
setupTransaction(obj, allInstances, type);
}
ch.write(dst);
// Update stats
++txStats.Objects;
txStats.Bytes += bbuf.position();
txStats.ObjectBytes += length;
// Done
return true;
}